﻿using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using IF.Utils;
using System.IO;
using Newtonsoft.Json.Linq;

namespace AnalysisAddress
{
    public partial class AnalysisAddres : Form
    {
        public AnalysisAddres()
        {
            InitializeComponent();
        }

        //路径
        private string path;

        private void button1_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(path) && string.IsNullOrEmpty(this.txt_Path.Text))
            {
                return;
            }
            if (string.IsNullOrEmpty(path) && !string.IsNullOrEmpty(this.txt_Path.Text))
            {
                path = this.txt_Path.Text.Trim();
            }
            this.bgw_Process.RunWorkerAsync();
        }

        //获取文件地址
        private void OrderImplrt_DragEnter(object sender, DragEventArgs e)
        {
            this.path = ((Array)e.Data.GetData(DataFormats.FileDrop)).GetValue(0).ToString();
            this.txt_Path.Text = this.path;
        }

        private void bgw_Process_DoWork(object sender, DoWorkEventArgs e)
        {
            StringBuilder sb = new StringBuilder();
            DataTable DT = NOPIHelper.RenderDataTableFromExcel(path, "Table1", 0);
            AddressClass.LoadResource(@"E:\我的项目\IF\IFStudio\AnalysisAddress\Resource\省市区.xls", "Table1");
            foreach (DataRow item in DT.Rows)
            {
                try
                {
                    bgw_Process.ReportProgress(1, AddressClass.GetAddress(item["收件地址"].ToString()));
                }
                catch (Exception)
                {
                    bgw_Process.ReportProgress(1, "----" + item["收件地址"].ToString());
                    continue;
                }
            }
            e.Result = "----------处理完成----------\r\n";
        }

        private void bgw_Process_ProgressChanged(object sender, ProgressChangedEventArgs e)
        {
            this.txt_ShowInfo.AppendText(e.UserState.ToString() + "\r\n");
        }

        private void bgw_Process_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            this.txt_ShowInfo.AppendText(e.Result.ToString());
        }

        private void btn_CancelOrder_Click(object sender, EventArgs e)
        {
            MaoyanUtil.CancelOrderPushDataParam();
        }
    }
}
